<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }

        div{
            width: 90%;
            margin: 50px  auto;
            height: 50px;
            background: pink;
            font-size: 30px;
            line-height: 50px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div>我是div</div>

    <script>
        // 获取div标签对象
        var oDiv = document.querySelector('div');

        // 页面大小监听事件
        window.addEventListener( 'resize' , function(){
            // 获取 页面的宽度 
            let width = document.documentElement.clientWidth ; 
            console.log( width );

            // 在 不同宽度下设定div标签的宽度比例
            if( width >= 1200 ){
                oDiv.style.width = '90%';
            }else if( width > 996 && width < 1200 ){
                oDiv.style.width = '70%';
            }else if( width > 768 && width < 996 ){
                oDiv.style.width = '50%';
            }else if( width < 768 ){
                oDiv.style.width = '30%';
            }
        })
    </script>
</body>
</html>